import { createRouter, createWebHashHistory } from "vue-router"
import Home from "../components/Home.vue"
import MarkDown from "../components/Common/MarkDown.vue"
import Login from "../components/LoginReg/Login.vue"
import Register from "../components/LoginReg/Register.vue"
import SuperAdminTenantList from "../components/SuperAdmin/TenantList.vue"
import SuperAdminModifyTenantInfoDialog from "../components/SuperAdmin/ModifyTenantInfoDialog.vue"
import OperationLog from "../components/MyTenant/OperationLog.vue"
import AccountMgr from "../components/MyTenant/AccountsMgr.vue"
import Billings from "../components/MyTenant/Billings.vue"
import EnvGroupMgr from "../components/Env/EnvGroup/EnvGroupMgr.vue"
import EnvTagMgr from "../components/Env/EnvTag/EnvTagMgr.vue"
import EnvMgr from "../components/Env/EnvMgr/EnvMgr.vue"
import CreateEnv from "../components/Env/EnvMgr/CreateEnv.vue"
import EditEnv from "../components/Env/EnvMgr/EditEnv.vue"
import RPAGroupMgr from "../components/RPA/RPAGroup/RPAGroupMgr.vue"
import RPATagMgr from "../components/RPA/RPATag/RPATagMgr.vue"
import RPAPoints from "../components/RPA/Log/Points.vue"
import RPAHistory from "../components/RPA/Log/History.vue"
import RPATask from "../components/RPA/RPATask/RPATaskMgr.vue"
import RPATaskFlow from "../components/RPA/RPATask/EditRPATaskFlow.vue"

// 2. 定义一些路由
// 每个路由都需要映射到一个组件。
// 我们后面再讨论嵌套路由。
const routes = [
    { path: '/', component: Home },
    { path: '/login', component: Login },
    { path: '/register', component: Register },
    { path: '/previewMD', component: MarkDown },
    {
      path: '/superAdminTenantMgr', 
      component: SuperAdminTenantList,
      meta: { 
        "title": "租户管理"  
      },
      children: [
        {
          path: 'modifyTenantInfo/:id',
          component: SuperAdminModifyTenantInfoDialog,
          meta: { 
            "title": "编辑租户信息"  
          }
        }
      ]
    },{
      path: '/myTenant/operationLog',
      component: OperationLog,
      meta: { 
        "title": "操作日志"  
      }
    },{
      path: '/myTenant/accountMgr',
      component: AccountMgr,
      meta: { 
        "title": "账号管理"  
      }
    },{
      path: '/myTenant/billings',
      component: Billings,
      meta: { 
        "title": "我的账单"  
      }
    },{
      path: '/env/envMgr',
      component: EnvMgr,
      meta: { 
        "title": "环境管理"  
      }
    },{
      path: '/env/envMgr/createEnv',
      component: CreateEnv,
      meta: { 
        "title": "创建环境"  
      }
    },{
      path: '/env/envMgr/editEnv/:id',
      component: EditEnv,
      meta: { 
        "title": "编辑环境"  
      }
    },{
      path: '/env/envGroupMgr',
      component: EnvGroupMgr,
      meta: { 
        "title": "环境分组"  
      }
    },{
      path: '/env/envTagMgr',
      component: EnvTagMgr,
      meta: { 
        "title": "环境标签"  
      }
    },{
      path: '/rpa/taskGroupMgr',
      component: RPAGroupMgr,
      meta: { 
        "title": "任务分组"  
      }
    },{
      path: '/rpa/taskTagMgr',
      component: RPATagMgr,
      meta: { 
        "title": "任务标签"  
      }
    },{
      path: '/rpa/history',
      component: RPAHistory,
      meta: { 
        "title": "任务详情"  
      }
    },{
      path: '/rpa/points',
      component: RPAPoints,
      meta: { 
        "title": "点数消费记录"  
      }
    },{
      path: '/rpa/task',
      component: RPATask,
      meta: { 
        "title": "任务管理"  
      }
    },{
      path: '/rpa/task/flow/:id',
      component: RPATaskFlow,
      meta: { 
        "title": "任务流程编辑"  
      }
    }

  ]
  
  // 3. 创建路由实例并传递 `routes` 配置
  // 你可以在这里输入更多的配置，但我们在这里
  // 暂时保持简单
export const router = createRouter({
    // 4. 内部提供了 history 模式的实现。为了简单起见，我们在这里使用 hash 模式。
    history: createWebHashHistory(),
    routes, // `routes: routes` 的缩写
})

router.beforeEach((to:any, from) => {
  if(to.meta.title){
    document.title = to.meta.title;
  }
})

